package com.huidao.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;

import com.huidao.entity.User;
import com.huidao.service.FunctionService;
import com.huidao.service.FunctionServiceImpl;

/**
 * Servlet Filter implementation class RoleFilter
 */
public class RoleFilter implements Filter {

    /**
     * Default constructor. 
     */
    public RoleFilter() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see Filter#destroy()
	 */
	public void destroy() {
		// TODO Auto-generated method stub
	}

	/**
	 * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
	 */
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		// TODO Auto-generated method stub
		// place your code here
		// pass the request along the filter chain
		
		HttpServletRequest req = (HttpServletRequest)request;
		String url = req.getServletPath();
		System.out.println(url);
//		String ss[] = url.split("/");
//		if(ss.length==3){
//			User user = (User) req.getSession().getAttribute("user");
//			String s = ss[1];
//			FunctionService service = new FunctionServiceImpl();
//			if(service.isFunction(user.getRole().getRoleId(), s)){
//				chain.doFilter(request, response);
//			}else{
//				response.getWriter().print("权限不足");
//			}
//		}else if(ss.length==2){
			chain.doFilter(request, response);
//		}else{
//			response.getWriter().print("权限不足");
//		}
	}

	/**
	 * @see Filter#init(FilterConfig)
	 */
	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
